package com.itheima.dubbo.web;

import com.itheima.dubbo.User;
import com.itheima.dubbo.UserInterface;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {
    @DubboReference
//    @DubboReference(timeout = 1900) // 消费方超时配置
//    @DubboReference(version = "dubbo.application.version")
//    @DubboReference(loadbalance = "roundrobin")   // 负载均衡策略修改
//    @DubboReference(check = false)   // 启动时不检查
//    @DubboReference(cluster = "failfast" )  // 容错机制 failfast 快速失败值，调用一次
    UserInterface userInterface;

    /**
     * hell
     * @param username
     * @return
     */
    @GetMapping("hello")
    public String hello(String username) {
        return userInterface.hello(username);
    }

    /**
     * 根据条件查询对象
     * @param id
     * @return
     */
    @GetMapping("getById")
    public User getById(Long id) {
        User user = new User();
        user.setId(id);

        // 设置隐式参数
        RpcContext.getContext().setAttachment("itname", "黑马程序员");

        return userInterface.getById(user);
    }
}
